package com.service.impl;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bean.CommentsMessage;
import com.bean.ZanMessage;
import com.dao.CommentsMessageDao;
import com.service.CommentsMessageService;
import com.util.LoggerUtil;
import com.util.Pager;
@Component
public class CommentsMessageServiceImpl implements CommentsMessageService{
	public static Logger logger=Logger.getLogger(CommentsMessageServiceImpl.class);
	@Autowired
	private CommentsMessageDao commentsMessageDao;

	@Override
	public Map<String, Object> insertCommentsMessage(String objId,String table,String userId,String content,JSONObject logs){
		return commentsMessageDao.insertCommentsMessage(objId, table, userId, content,logs);
	}

	@Override
	public Map<String, Object> selectPageList(Integer curPage,
			Integer pageSize, String objId, String table, String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Pager<CommentsMessage> pager=commentsMessageDao.selectPageList(curPage, pageSize, objId, table, userId);
			
			if(pager!=null&&pager.getData().size()>0){
				map.put("result", "success");
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "{}");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

	@Override
	public Map<String, Object> selectByWhoZanMyComment(Integer curPage,
			Integer pageSize, String userId,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			Pager<ZanMessage> pager=commentsMessageDao.selectByWhoZanMyComment(curPage, pageSize, userId);
			
			if(pager!=null&&pager.getData().size()>0){
				map.put("result", "success");
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}

	@Override
	public Map<String, Object> selectList(Integer curPage, Integer pageSize,
			String userId,String table,JSONObject logs) {
		Map<String, Object> map=new HashMap<String, Object>();
		Pager<Object> pager=commentsMessageDao.selectList(curPage, pageSize, userId,table);
		
		try {
			if(pager!=null&&pager.getData().size()>0){
				map.put("result", "success");
				map.put("rows", pager);
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
	
	
}
